part of '../repository.dart';

const _kCustomCollectionDataIdKey = 'id';
const _kCustomCollectionDataTitleKey = 'title';
const _kCustomCollectionDataLexicalItemIdsKey = 'lexical_item_ids';

const _kCustomCollectionDataTypeValue = 'custom_collection';

class _CustomCollectionDataDto extends Equatable implements _CustomCollectionListItemDataDto {
  const _CustomCollectionDataDto._internal({
    required this.id,
    required this.title,
    required this.lexicalItemIds,
  });

  final String id;
  final String title;
  final BuiltSet<String> lexicalItemIds;

  @override
  String get type => _kCustomCollectionDataTypeValue;

  @override
  List<Object?> get props {
    return [
      id,
      title,
      lexicalItemIds,
    ];
  }

  factory _CustomCollectionDataDto.fromJson(Map<String, dynamic> json) {
    final lexicalItemIds = BuiltSet<String>.from(json[_kCustomCollectionDataLexicalItemIdsKey]);

    return _CustomCollectionDataDto._internal(
      id: json[_kCustomCollectionDataIdKey],
      title: json[_kCustomCollectionDataTitleKey],
      lexicalItemIds: lexicalItemIds,
    );
  }

  factory _CustomCollectionDataDto.fromEntity(BackupCustomCollectionData collection) {
    return _CustomCollectionDataDto._internal(
      id: collection.id,
      title: collection.title,
      lexicalItemIds: collection.lexicalItemIds,
    );
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      _kCustomLexicalItemTypeKey: type,
      _kCustomCollectionDataIdKey: id,
      _kCustomCollectionDataTitleKey: title,
      _kCustomCollectionDataLexicalItemIdsKey: lexicalItemIds.toList(),
    };
  }

  @override
  BackupCustomCollectionData toEntity() {
    return BackupCustomCollectionData(
      id: id,
      title: title,
      lexicalItemIds: lexicalItemIds,
    );
  }
}
